﻿//++
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
// Module Name:
//
//  TaskCompletedEventArgs.cs
//    
// Abstract:
//
//  This module implements the TaskCompletedEventArgs class.
//
//--

using System;
using System.Collections.Generic;
using System.Diagnostics;

using Microsoft.OfficeCommunicationsServer.Applications.Common;

namespace Microsoft.EnhancedReminders.Scheduler
{
    internal class TaskCompletedEventArgs : EventArgs
    {
        // Task context
        private readonly TaskContext _taskContext;

        // Error
        private readonly Exception _error;

        /// <summary>
        /// ctor.
        /// </summary>
        /// <param name="taskContext">Task context</param>
        internal TaskCompletedEventArgs(TaskContext taskContext)
            : this(taskContext, null)
        {
        }

        /// <summary>
        /// ctor.
        /// </summary>
        /// <param name="taskContext">Task context</param>
        /// <param name="error">Error</param>
        internal TaskCompletedEventArgs(TaskContext taskContext, Exception error)
        {
            Debug.Assert(taskContext != null, "taskContext != null");
            Debug.Assert(taskContext.Context != null, "taskContext.Context != null");

            _taskContext = taskContext;
            _error = error;
        }

        /// <summary>
        /// Returns the logging context.
        /// </summary>
        internal Context Context
        {
            get
            {
                return _taskContext.Context;
            }
        }

        /// <summary>
        /// Returns the task context.
        /// </summary>
        internal TaskContext TaskContext
        {
            get
            {
                return _taskContext;
            }
        }

        /// <summary>
        /// Returns the error.
        /// </summary>
        internal Exception Error
        {
            get
            {
                return _error;
            }
        }
    }

    internal class GetItemTaskCompletedEventArgs : TaskCompletedEventArgs
    {
        // Retrieved mailbox item
        private readonly ItemType _item;

        /// <summary>
        /// ctor.
        /// </summary>
        /// <param name="taskContext">Task context</param>
        /// <param name="item">Retrieved mailbox item</param>
        internal GetItemTaskCompletedEventArgs(TaskContext taskContext, ItemType item)
            : base(taskContext)
        {
            _item = item;
        }

        /// <summary>
        /// Returns the retrieved mailbox item.
        /// </summary>
        internal ItemType Item
        {
            get
            {
                return _item;
            }
        }
    }

    /// <summary>
    /// Event arguments used when fetching a specific instance of a recurring meeting or appointment
    /// completes.
    /// </summary>
    internal class GetNextRecurringItemTaskCompletedEventArgs : GetItemTaskCompletedEventArgs
    {
        // The ReminderItem that is associated with the master item of a recurring meeting.
        private readonly ReminderItem _reminderItem;

        // The ItemId of the master item for a fetched recurring instance of an appointment or meeting.
        private readonly ItemIdType _masterItemId;

        /// <summary>
        /// ctor.
        /// </summary>
        /// <param name="taskContext">Task context</param>
        /// <param name="item">Retrieved mailbox item</param>
        /// <param name="reminderItem">ReminderItem associated with the next occurrence of the meeting</param>
        /// <param name="masterItemId">ItemId of the recurring master</param>
        internal GetNextRecurringItemTaskCompletedEventArgs(TaskContext taskContext, ItemType item, ReminderItem reminderItem, ItemIdType masterItemId)
            : base(taskContext, item)
        {
            _reminderItem = reminderItem;
            _masterItemId = masterItemId;
        }

        /// <summary>
        /// The ReminderItem that is associated with the master item of a recurring meeting.
        /// </summary>
        internal ReminderItem ReminderItem
        {
            get
            {
                return _reminderItem;
            }
        }

        /// <summary>
        /// The ItemId of the master item for a fetched recurring instance of an appointment or meeting.
        /// </summary>
        internal ItemIdType MasterItemId
        {
            get
            {
                return _masterItemId;
            }
        }
    }

    internal class GetItemWithAttachmentTaskCompletedEventArgs : GetItemTaskCompletedEventArgs
    {
        // File attachment on the retrieved mailbox item
        private readonly FileAttachmentType _fileAttachment;

        /// <summary>
        /// ctor.
        /// </summary>
        /// <param name="taskContext">Task context</param>
        /// <param name="item">Retrieved mailbox item</param>
        /// <param name="fileAttachment">File attachment on the retrieved mailbox item</param>
        internal GetItemWithAttachmentTaskCompletedEventArgs(TaskContext taskContext, ItemType item, FileAttachmentType fileAttachment)
            : base(taskContext, item)
        {
            _fileAttachment = fileAttachment;
        }

        /// <summary>
        /// Returns the file attachment on the retrieved mailbox item.
        /// </summary>
        internal FileAttachmentType FileAttachment
        {
            get
            {
                return _fileAttachment;
            }
        }
    }

    internal class UpdateMonitorTaskCompletedEventArgs : TaskCompletedEventArgs
    {
        // Search folder created during the update
        private readonly BaseFolderIdType _searchFolderId;

        // Items in the created search folder
        private readonly ItemIdType[] _items;

        /// <summary>
        /// ctor.
        /// </summary>
        /// <param name="taskContext">Task context</param>
        /// <param name="searchFolderId">Search folder created during the update</param>
        /// <param name="items">Items in the created search folder</param>
        internal UpdateMonitorTaskCompletedEventArgs(TaskContext taskContext, BaseFolderIdType searchFolderId, ItemIdType[] items)
            : this(taskContext, searchFolderId, items, null)
        {
        }

        /// <summary>
        /// ctor.
        /// </summary>
        /// <param name="taskContext">Task context</param>
        /// <param name="searchFolderId">Search folder created during the update</param>
        /// <param name="items">Items in the created search folder</param>
        /// <param name="error">Error</param>
        internal UpdateMonitorTaskCompletedEventArgs(TaskContext taskContext, BaseFolderIdType searchFolderId, ItemIdType[] items, Exception error)
            : base(taskContext, error)
        {
            _searchFolderId = searchFolderId;
            _items = items;
        }

        /// <summary>
        /// Returns the search folder created during the update.
        /// </summary>
        internal BaseFolderIdType SearchFolderId
        {
            get
            {
                return _searchFolderId;
            }
        }

        /// <summary>
        /// Returns the items in the created search folder.
        /// </summary>
        internal ItemIdType[] Items
        {
            get
            {
                return _items;
            }
        }
    }

    internal class FindItemTaskCompletedEventArgs : TaskCompletedEventArgs
    {
        // Found mailbox items
        private readonly ItemIdType[] _items;

        /// <summary>
        /// ctor.
        /// </summary>
        /// <param name="taskContext">Task context</param>
        /// <param name="items">Found mailbox items</param>
        internal FindItemTaskCompletedEventArgs(TaskContext taskContext, ItemIdType[] items)
            : base(taskContext)
        {
            _items = items;
        }

        /// <summary>
        /// Returns the found mailbox items.
        /// </summary>
        internal ItemIdType[] Items
        {
            get
            {
                return _items;
            }
        }
    }

    internal class GetDistinguishedFolderTaskCompletedEventArgs : TaskCompletedEventArgs
    {
        // Mapping between folder ID and distinguished folder name
        private readonly Dictionary<FolderIdType, DistinguishedFolderIdNameType> _folderIdTable;

        /// <summary>
        /// ctor.
        /// </summary>
        /// <param name="taskContext">Task context</param>
        /// <param name="folderIdTable">Mapping between folder ID and distinguished folder name</param>
        internal GetDistinguishedFolderTaskCompletedEventArgs(TaskContext taskContext, Dictionary<FolderIdType, DistinguishedFolderIdNameType> folderIdTable)
            : base(taskContext)
        {
            _folderIdTable = folderIdTable;
        }

        /// <summary>
        /// Returns the mapping between folder ID and distinguished folder name.
        /// </summary>
        internal Dictionary<FolderIdType, DistinguishedFolderIdNameType> FolderIdTable
        {
            get
            {
                return _folderIdTable;
            }
        }
    }
}
